package com.text.viewpageviewpage;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import java.util.List;

/**
 * @description：TODO
 * @Author MRyan
 * @Date 2020/3/18 20:35
 * @Version 1.0
 */
public class MyPageAdapter extends PagerAdapter {

    public List<View> mViews;
    private Context context;

    public MyPageAdapter(List<View> mViews, MainActivity context) {
        this.mViews = mViews;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mViews.size();
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull View container, int position) {
        ((ViewPager) container).addView(mViews.get(position));
        return mViews.get(position);

    }

    @Override
    public void destroyItem(@NonNull View container, int position, @NonNull Object object) {
        ((ViewPager) container).removeView(mViews.get(position));
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return (view == o);
    }
}
